﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace StuApart
{
    public partial class ForIn : Form
    {
        public ForIn()
        {
            InitializeComponent();
        }

        private void forInBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {

            if (nameTextBox.Text.Length == 0)
            {
                MessageBox.Show("姓名不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                nameTextBox.Focus();
                return;
            }
            try
            {
                this.Validate();
                this.forInBindingSource.EndEdit();
                this.tableAdapterManager.UpdateAll(this.stuApartDataSet);

                MessageBox.Show("保存成功");
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, "保存失败");
            }
        }

        private void ForIn_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“stuApartDataSet.ForIn”中。您可以根据需要移动或移除它。
            this.forInTableAdapter.Fill(this.stuApartDataSet.ForIn);
        }

        private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
        {
            if (forInDataGridView.SelectedRows.Count == 0)
            {
                MessageBox.Show("请先单击最左边的空白处，选择要删除的行，" + "按住CTRL或Shift键可同时选择多行");
            }
            else
            {
                if (MessageBox.Show("确定要删除选定的行吗？", "小心", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    for (int i = 0; i < forInDataGridView.SelectedRows.Count; i++)
                    {
                        forInBindingSource.RemoveAt(forInDataGridView.SelectedRows[i].Index);
                    }
                }
            }
        }
    }
}